package com.chenjt.netty.eleven_bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;

import java.util.Iterator;

/**
 * 注释：复合缓冲区
 *
 * @author chenjt
 * @date 2024/9/4 10:31
 */
public class CompositeBuffer {

    public static void main(String[] args) {
        CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer();

        ByteBuf headBuf = Unpooled.buffer(10);// 堆缓冲
        ByteBuf directBuf = Unpooled.directBuffer(8);// 直接缓冲

        compositeByteBuf.addComponents(headBuf,directBuf);
        compositeByteBuf.removeComponent(0);

        Iterator<ByteBuf> iter = compositeByteBuf.iterator();
        while(iter.hasNext()){
            System.out.println(iter.next());
        }

        compositeByteBuf.forEach(System.out::println);

    }


}
